<html>
<head><meta charset="utf-8"><title>cross-lang-lto and assembly · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html">cross-lang-lto and assembly</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="152207262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152207262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152207262">(Dec 19 2018 at 19:41)</a>:</h4>
<p>Hey @mw, do you know of any reason that cross-language LTO shouldn't work if my C file is actually an assembly file?</p>



<a name="152207321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152207321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152207321">(Dec 19 2018 at 19:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> Yeah, that I think would be expected -- LLVM doesn't uplift assembly into LLVM IR so it can't run optimization passes based on it?</p>
<p>Not sure if that's what you mean though</p>



<a name="152207364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152207364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152207364">(Dec 19 2018 at 19:43)</a>:</h4>
<p>I don't think I phrased my question well, let me try again: Do you think cross-language LTO will work when the two languages are Rust + assembly?</p>



<a name="152207412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152207412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152207412">(Dec 19 2018 at 19:44)</a>:</h4>
<p>I have not tried anything, so I have no clue ;-)</p>



<a name="152207435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152207435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152207435">(Dec 19 2018 at 19:44)</a>:</h4>
<p>But, if I understand you correctly, cross-language LTO only works when there's LLVM IR available. Assembly wouldn't have that, so LTO is <strong>not</strong> possible?</p>



<a name="152207551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152207551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152207551">(Dec 19 2018 at 19:46)</a>:</h4>
<p>I suppose it depends on definition of LTO -- LLVM might be able to strip out symbols/reduce code size by inlining still, I guess</p>



<a name="152207579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152207579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152207579">(Dec 19 2018 at 19:47)</a>:</h4>
<p>But the "intelligent" optimization I think wouldn't happen</p>



<a name="152208572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152208572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152208572">(Dec 19 2018 at 20:00)</a>:</h4>
<p>AFAIK there is no existing infrastructure in LLVM for doing any non-trivial optimizing starting from textual assembly (beyond what linkers could already do). Even the low level machine-specific peephole optimizations work on a much richer IR (MachineInstr) than what LLVM can get back out of textual assembly (MCInstr).</p>



<a name="152210983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152210983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152210983">(Dec 19 2018 at 20:34)</a>:</h4>
<p>I'm thinking even beyond text — if I have two fully compiled object files (just machine code), can those somehow be optimized (esp. inlined) with each other?</p>



<a name="152211130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152211130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152211130">(Dec 19 2018 at 20:36)</a>:</h4>
<p>Like, I guess I got mislead by the belief that "linkers just combine machine code", thus link-time optimization would be on that machine code. However, in this case we have enhanced object files that also have LLVM IR in it, so "link time" is <em>also</em> "code generation time"</p>



<a name="152214891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152214891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152214891">(Dec 19 2018 at 21:34)</a>:</h4>
<p>FWIW object file vs textual asm isn't a big difference in any way that matters for this subject</p>



<a name="152216987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152216987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152216987">(Dec 19 2018 at 22:09)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> what matters is ability to inline</p>



<a name="152216996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152216996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152216996">(Dec 19 2018 at 22:09)</a>:</h4>
<p>object file produced from external assembly will not be able to get rid of the call-overhead</p>



<a name="152217396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152217396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152217396">(Dec 19 2018 at 22:17)</a>:</h4>
<p>though in practice it seems seldom necessary</p>



<a name="152242538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/cross-lang-lto%20and%20assembly/near/152242538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mw <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/cross-lang-lto.20and.20assembly.html#152242538">(Dec 20 2018 at 08:52)</a>:</h4>
<p>Yes, as the others already mentioned, cross-lang LTO needs LLVM IR for all code involved in order to do anything useful. Linkers can handle mixes of LLVM IR and regular libs/object files but the latter won't take part in the optimization passes.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>